package com.campus.handler;

import com.campus.exception.BusinessException;
import com.campus.response.Code;
import com.campus.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public ResponseResult<Object> businessExceptionHandle(BusinessException e){
        return new ResponseResult<>(e.getCode(),e.getMessage(),null);
    }
    @ExceptionHandler(Exception.class)
    public ResponseResult<Object> exceptionHandle(Exception e){
        log.error("出现系统错误：{}", e.getMessage());
        return new ResponseResult<>(Code.ERROR_CODE,Code.ERROR_MESSAGE,null);
    }
}
